﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPIDesktopClient.Interface;
using PPIDesktopClient.Presenter;
using PPIDesktopClient.Entities;

namespace PPIDesktopClient
{
    public partial class frmVisitEditor : frmDialogBase
    {
        private PoleEditorPresenter m_Presenter;
        private EVendor_Visit_XMissionStructure m_Visit;

        public frmVisitEditor()
        {
            InitializeComponent();
            //m_Presenter = new PoleEditorPresenter(this);
        }

        private void frmVisitEditor_Load(object sender, EventArgs e)
        {
            if(this.OnLoad != null)
            {
                this.OnLoad(this,new EventArgs());
            }
        }

        #region IVisitEditor Members

        public EVendor_Visit_XMissionStructure Visit
        {
            get
            {
                return m_Visit;
            }
            set
            {
                m_Visit = value;
            }
        }

        public int VisitId
        {
            get { throw new NotImplementedException(); }
        }

        public int ProgressBarValue
        {
            set { throw new NotImplementedException(); }
        }

        public event EventHandler<EventArgs> OnSave;

        public new event EventHandler<EventArgs> OnLoad;

        public void LoadData()
        {
            if (m_Visit.Vendor_Project.Vendor_ProjectId != Int32.MinValue)
                ddlProject.SelectedIndex = PPIDesktopClient.General.UIHelper.GetItemIndex(ddlProject, m_Visit.Vendor_Project.Vendor_ProjectId.ToString());

            if (m_Visit.Vendor_Visit_Type.Vendor_Visit_TypeId != Int32.MinValue)
                ddlVisitTypes.SelectedIndex = PPIDesktopClient.General.UIHelper.GetItemIndex(ddlVisitTypes, m_Visit.Vendor_Visit_Type.Vendor_Visit_TypeId.ToString());

            if (m_Visit.TopType.XMissionStructures_TopTypeId != Int32.MinValue)
                ddlTopType.SelectedIndex = PPIDesktopClient.General.UIHelper.GetItemIndex(ddlTopType, m_Visit.TopType.XMissionStructures_TopTypeId.ToString());

            if (m_Visit.Vendor_Contact.Vendor_ContactId != Int32.MinValue)
                ddlContact.SelectedIndex = PPIDesktopClient.General.UIHelper.GetItemIndex(ddlContact, m_Visit.Vendor_Contact.Vendor_ContactId.ToString());
            if (m_Visit.Date != DateTime.MinValue)
                dateDate.Value = m_Visit.Date;
            if (m_Visit.Handheld.Id != Int32.MinValue)
                ddlHandheld.SelectedIndex = PPIDesktopClient.General.UIHelper.GetItemIndex(ddlHandheld, m_Visit.Handheld.Id.ToString());

            crtlPositionStructure.SetAltitude(m_Visit.Altitude);
            crtlPositionStructure.SetLatitude(m_Visit.Latitude);
            crtlPositionStructure.SetLongitude(m_Visit.Longitude);
            crtlPositionStructure.SetSatelliteCount(m_Visit.SatelliteCount);
            crtlPositionStructure.SetSatelliteTime(m_Visit.SatelliteTime);

            lstPoles.Items.Clear();
            foreach (EVendor_Visit_XMissionStructures_Pole p in m_Visit.Poles)
            {
                lstPoles.Items.Add(p);
            }
            ddlListImages.Items.Clear();
            ddlImagesPole.Items.Clear();
            lstImagesPoles.Items.Clear();
            foreach (EVendor_Visit_XMissionStructures_Image i in m_Visit.Images)
            {
                ddlListImages.Items.Add(i);
                ddlImagesPole.Items.Add(i);
            }
            
        }

        #endregion
    }
}
